package MaintMenu.PoAnalysis;

import MaintMenu.VenPricingUpdMasterFiles.SQLUpdStm;

import java.sql.*;
import java.text.NumberFormat;

/**
 * Created with IntelliJ IDEA.
 * User: Jason
 * Date: 7/11/13
 * Time: 2:20 PM
 * To change this template use File | Settings | File Templates.
 */
public class CostCal {

    String cif="";
    public String comparePrice(double prot, double depo, double tyg_tx, double ks, double tyg_tw, double gd, double kv, double gn) {
        //Reset the following vendor pricing to 0.00 to make them excluded in POAnalysis
        prot=0.00D;
        ks=0.00D;
        gd=0.00D;


        //reset cif to "";
        cif="";
//        System.out.println("cif should be null :"+cif);
        double bestPrice = 9999D;
        String bestCompany = "null";
        NumberFormat df = NumberFormat.getCurrencyInstance();

        if (prot > 0.0D && prot  < bestPrice) {
            bestPrice = prot ;
            bestCompany = "prot";
            cif = "PT";
        }
        if (depo > 0.0D && depo < bestPrice) {
            bestPrice = depo;
            bestCompany = "depo";
            cif = "DP";
        }
        if (tyg_tx > 0.0D && tyg_tx < bestPrice) {
            bestPrice = tyg_tx;
            bestCompany = "tyg_tx";
            cif = "TX";
        }
        if (ks > 0.0D && ks < bestPrice) {
            bestPrice = ks;
            bestCompany = "ks";
            cif = "KS";
        }
        if (tyg_tw > 0.0D && tyg_tw < bestPrice) {
            bestPrice = tyg_tw;
            bestCompany = "tyg_tw";
            cif = "TY";
        }
        if (gd > 0.0D && gd  < bestPrice) {
            bestPrice = gd ;
            bestCompany = "gd";
            cif = "GD";
        }
        if (kv > 0.0D && kv  < bestPrice) {
            bestPrice = kv ;
            bestCompany = "kv";
            cif = "KV";
        }
        if (gn > 0.0D && gn  < bestPrice) {
            bestPrice = gn ;
            bestCompany = "gn";
            cif = "GN";
//            cif = "GN";
        }
        if ( prot+depo+tyg_tx+ks+tyg_tw+gd+kv+gn==0) {
            bestPrice = 0.00 ;
//            bestCompany = "gn";
            cif = "*NO PRC*";
        }
//        }else if( prot+depo+tyg_tx+ks+tyg_tw+gd+kv+gn!=0)  {
//            cif = "NA";
//        }


//        System.out.println("Best Price :"+bestPrice);


//        System.out.println(cif);
        return cif;
    }
//    "update tblbcn set supplier = 'AP-(GD)' where [part#] = '" + part + "

//    public CostCal(String table,String supplier,String plNum, String tw,String tx,String gn,String dp,String ap,String ycc){
//
//        //create statement object
//
//
//
//        try {
//            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//            String dataSourceName = "dbLI";
//            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
//            Connection conli = DriverManager.getConnection(dbURL, "", "");
//
//
//            String st[] = new String[1];
//
//            st[0] = "update " + table + " set supplier = '"+supplier+"' where [part#] = '" + plNum + "'";
////            System.out.println(st[0]);
//
//
//
//
////             /* update LT_MAST11 master file */
////            whereA="where a.depo_prc";
////            whereB="b.[unit price]";
////            whereoperator="<>";
////            tableA =    "LT_MAST1";
////            tableB =    "_costdepo";
////            onA=        "partlink";
////            onB=        "PartsLink1";
////
////            fieldA1=    "oem_no";       //part_no  (oem#)
////            fieldB1=    "[OEM 1]";
////
////            fieldA2=    "DEPO_NO";       //DEPOT #
////            fieldB2=    "[DEPO NO]";
////
////            fieldA3=    "DEPO_PRC";      //PRICE
////            fieldB3=    "[UNIT PRICE]";
////
////            fieldA4=    "DEPO_PKG";
////            fieldB4=    "[Qty Ctn]";
////            st[2] = stm.StmExecute(tableA,tableB,whereA,whereB,whereoperator,onA,onB,fieldA1,fieldB1,fieldA2,fieldB2,fieldA3,fieldB3,fieldA4,fieldB4);
////            System.out.println(st[2]);
//
//            for (int x=0; x<st.length;x++){
//                Statement stli = conli.createStatement();
//
//                try {
//                    System.out.println("Script :"+st[x]);
//                    int rowsupdated = stli.executeUpdate(st[x]);
//                    System.out.println("Total record Updated : "+rowsupdated);
//                    //JOptionPane.showOptionDialog(null, "Statement : " + st[x] + "\n\nTotal record Updated : " + rowsupdated, "Update Complete", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null);
//
//                }catch(SQLException er) {
//                    er.printStackTrace();
//                }stli.close(); }
//        }
//        catch(Exception e){
//            e.printStackTrace();
//        }
//    }
}
